package thread;

import java.util.Scanner;

public class demo21 {
    public static void main(String[] args) {
        Object locker=new Object();
        Thread t1=new Thread(()->{
            synchronized (locker){
                System.out.println("t1 wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1线程被唤醒");
        });
        Thread t2=new Thread(()->{

            synchronized (locker){
                System.out.println("t2 wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t2线程被唤醒");
        });
        Thread t3=new Thread(()->{
            synchronized (locker){
                System.out.println("输入任意之后唤醒所有线程线程");
                Scanner scanner=new Scanner(System.in);
                scanner.next();
                //locker.notify();
                locker.notifyAll();
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
